/*
 * LoginForm.java
 *
 * Created on August 29, 2007, 11:01 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package tcc.gui.web.struts.login;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import tcc.domain.login.TCCSystemUser;

/**
 *
 * @author Diego
 */
public class LoginForm extends ActionForm{
    
    /** Creates a new instance of LoginForm */
    public LoginForm() {
    }
    
    private TCCSystemUser systemUser =  new TCCSystemUser();
    
    public TCCSystemUser getSystemUser() {
        return systemUser;
    }
    
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        
        //errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage("erro.login"));
        
        if(this.getSystemUser().getLogin()== null || this.getSystemUser().getLogin().equals("")){ 
            errors.add("systemUser.login", new ActionMessage("Login.jsp.login.null"));
        }
        if(this.getSystemUser().getPassword()== null || this.getSystemUser().getPassword().equals("")){ 
            errors.add("systemUser.password", new ActionMessage("Login.jsp.password.null"));
        }
        return errors;
    }
    
    @Override
    public void reset(ActionMapping action, HttpServletRequest request){
        this.systemUser = new TCCSystemUser();
    }
    
    
}
